<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>window对象</title>
    <!--setTimeout、clearTimeout-->
</head>
<body>

<button onclick="fn1()">设置延时任务</button>
<button onclick="fn2()">取消延时任务</button>
</body>

<script>

    var id;
    /**
     * 设置延时任务
     */
    function fn1() {
        console.log(new Date());
        id = window.setTimeout("showTime()",5000);
    }


    /**
     * 取消延时任务
     */
    function fn2() {
        window.clearTimeout(id);
    }

    /**
     * 显示当前时间
     */
    function showTime() {
        console.log(new Date());
    }

</script>
</html>>